/*
 * Copyright (c) 18/7/14 . All Rights Reserved.
 */
package com.cgmnx.admin.service;

import com.google.common.util.concurrent.AbstractIdleService;
import com.google.common.util.concurrent.MoreExecutors;

/**
 * @author: z Date: 18/7/14 Time: 下午7:12
 * @version: 1.0.0
 */
public class AbstractIdleServiceTest extends AbstractIdleService {
    public static void main(String[] args) {
        AbstractIdleServiceTest client = new AbstractIdleServiceTest();
        client.addListener(new Listener() {
            @Override
            public void starting() {
                System.out.println("服务开始启动.....");
            }

            @Override
            public void running() {
                System.out.println("服务开始运行");
                ;
            }

            @Override
            public void stopping(State from) {
                System.out.println("服务关闭中");
            }

            @Override
            public void terminated(State from) {
                System.out.println("服务终止");
            }

            @Override
            public void failed(State from, Throwable failure) {
                System.out.println("失败，cause：" + failure.getCause());
            }
        }, MoreExecutors.directExecutor());
        client.executor();
    }

    @Override
    protected void startUp() throws Exception {
        System.out.println("开始就开始呗");
    }

    @Override
    protected void shutDown() throws Exception {
        System.out.println("结束就结束呗");
    }
}
